package com.sxzt.core.result;

import com.sxzt.core.data.BaseResponse;
import com.sxzt.core.enum_status.BaseOut;
import com.sxzt.core.enum_status.DefaultBusinessStatus;
import io.vavr.Function0;
import io.vavr.Function1;
import io.vavr.Function2;
import io.vavr.Function3;

/**
 * @author fly
 * @param <T> 参数泛型
 */
public abstract class DefaultResult<T> implements Result<T> {


    public BaseResponse<T> ok() {
        return success();
    }

    public BaseResponse<T> failed() {
        return error();
    }

    public BaseResponse<T> ok(String message) {
        return makeResult(DefaultBusinessStatus.SUCCESS, null).setMsg(message);
    }

    public BaseResponse<T> ok(String message, T data) {
        return makeResult(DefaultBusinessStatus.SUCCESS, data).setMsg(message);
    }

    public BaseResponse<T> ok(T data) {
        return makeResult(DefaultBusinessStatus.SUCCESS, data);
    }

    public BaseResponse<T> ok(String message, Function0<T> data) {
        return ok(message, Function0.of(data).memoized().apply());
    }

    public <A> BaseResponse<T> ok(String message, A var1, Function1<A, T> data) {
        return ok(message, Function1.of(data).memoized().apply(var1));
    }

    public  <A, B> BaseResponse<T> ok(String message, A var1, B var2, Function2<A, B, T> data) {
        return ok(message, Function2.of(data).memoized().apply(var1, var2));
    }

    public  <A, B, C> BaseResponse<T> ok(String message, A var1, B var2, C var3, Function3<A, B, C, T> data) {
        return ok(message, Function3.of(data).memoized().apply(var1, var2, var3));
    }

    public BaseResponse<T> failed(String message) {
        return makeResult(DefaultBusinessStatus.ERROR, null).setMsg(message);
    }

    public BaseResponse<T> failed(String message, T data) {
        return makeResult(DefaultBusinessStatus.ERROR, data).setMsg(message);
    }

    public BaseResponse<T> failed(T data) {
        return makeResult(DefaultBusinessStatus.ERROR, data);
    }

    public BaseResponse<T> lift(BaseOut baseOut) {
        return makeResult(DefaultBusinessStatus.SUCCESS, null).setCode(baseOut.getCode())
                .setMsg(baseOut.getMes());
    }

    public BaseResponse<T> lift(BaseOut baseOut, T data) {
        return makeResult(DefaultBusinessStatus.SUCCESS, data).setCode(baseOut.getCode())
                .setMsg(baseOut.getMes());
    }



}
